<?php

namespace app\admin\controller;

class Index extends Base
{
    public function index(): void
    {
        $request = $this->request;

        //顶部横向菜单
        $modelAdminMenu = model('AdminMenu');
        $where['topid'] = 0;
        $where['status'] = 1;
        $list = $modelAdminMenu->getList($where);
        $this->assign('list', $list);

        //左侧纵向菜单
        $listSub = $modelAdminMenu->getPurview();
        $this->assign('listSub', $listSub);

        //版本信息
        $this->assign('version', 1.0);

        //引导
        $whereGuide['status'] = 1;
        $listGuide = model('Guide')->getList($whereGuide, 'sort asc');
        $this->assign('listGuide', $listGuide);

        $this->fetch('index');
    }

    //版本切换
    public function switchVersion()
    {
        $infoConfig = model('Config')->getInfo();
        if ($infoConfig['switchVersion'] == 1) {
            $switchVersion = 2;
        } else {
            $switchVersion = 1;
        }
        model('Config')->saved(['name' => 'switchVersion'], ['data' => $switchVersion]);

        jsonApi(1, '切换成功');
    }

    //清理缓存
    public function delCache()
    {
        setLog('清理缓存');
        clear();

        jsonApi(1, '清理缓存成功');
    }

}
